/**
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 */
package org.jiopi.ibean.kernel.util;

import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;

public class PackageMergerTestCase {
	
	@Test public void PackageMerger_Right(){
		{
			String[] exportClasses = new String[]{
					"org.example.a.b.Class1",
					"org.example.a.b.Class2",
					"org.example.a.c.Class3",
					"org.example.a.c.Class4",
					"org.example.z.Class5",
					"org.example.z.CLass6",
					"org.example.x.CLass7"
			};
			String[] otherClasses = new String[]{
					"org.example.x.CLass8",
					"org.example.x.CLass9"
			};
			String[] exportPackages = new String[]{
					"org.example.a.**",
					"org.example.z.*",
					"org.example.x.CLass7"
			};
			
			PackageMerger pm = new PackageMerger();
			for(String className:exportClasses){
				pm.addClass(className, true,false);
			}
			for(String className:otherClasses){
				pm.addClass(className, false,false);
			}
			String[] exportedPackages = pm.getExportPackages();

			assertArrayEquals(exportPackages,exportedPackages);
		}
		
		{
			String[] exportClasses = new String[]{
					"org.example.a.b.Class1",
					"org.example.a.b.Class2",
					"org.example.a.b.Class3"
			};
			String[] otherClasses = new String[]{
			};
			String[] exportPackages = new String[]{
					"org.example.a.b.*",
			};
			
			PackageMerger pm = new PackageMerger();
			for(String className:exportClasses){
				pm.addClass(className, true,false);
			}
			for(String className:otherClasses){
				pm.addClass(className, false,false);
			}
			String[] exportedPackages = pm.getExportPackages();

			assertArrayEquals(exportPackages,exportedPackages);
		}
		
		{
			String[] exportClasses = new String[]{
					"org.example.a.b.Class1",
					"org.example.a.b.Class2",
					"org.example.a.b.Class3",
					"org.example.a.b.c.Class5"
			};
			String[] otherClasses = new String[]{
					"org.example.a.b.c.Class4"
			};
			String[] exportPackages = new String[]{
					"org.example.a.b.c.Class5",
					"org.example.a.b.*"
			};
			
			PackageMerger pm = new PackageMerger();
			for(String className:exportClasses){
				pm.addClass(className, true,false);
			}
			for(String className:otherClasses){
				pm.addClass(className, false,false);
			}
			String[] exportedPackages = pm.getExportPackages();
			assertArrayEquals(exportPackages,exportedPackages);
		}
		
		{
			String[] exportClasses = new String[]{
					"org.example.a.b.Class1",
					"org.example.a.b.Class2",
					"org.example.a.b.Class3",
			};
			String[] otherClasses = new String[]{
					"org.example.a.b.c.Class5"
			};
			String[] exportPackages = new String[]{
					"org.example.a.b.*"
			};
			
			PackageMerger pm = new PackageMerger();
			for(String className:exportClasses){
				pm.addClass(className, true,false);
			}
			for(String className:otherClasses){
				pm.addClass(className, false,false);
			}
			String[] exportedPackages = pm.getExportPackages();
			
			assertArrayEquals(exportPackages,exportedPackages);
		}
		{
			String[] exportClasses = new String[]{
					"org.example.a.b.Class1",
					"org.example.a.b.Class2",
					"org.example.a.b.Class3",
					"org.example.a.c.Class4",
			};
			String[] otherClasses = new String[]{
					
			};
			String[] exportPackages = new String[]{
					"org.example.a.**"
			};
			
			PackageMerger pm = new PackageMerger();
			for(String className:exportClasses){
				pm.addClass(className, true,false);
			}
			for(String className:otherClasses){
				pm.addClass(className, false,false);
			}
			String[] exportedPackages = pm.getExportPackages();
			
			assertArrayEquals(exportPackages,exportedPackages);
		}
		{
			String[] exportClasses = new String[]{
					"org.example.a.b.Class1",
					"org.example.a.b.Class2",
					"org.example.a.b.Class3",
					"org.example.a.c.Class4",
			};
			String[] otherClasses = new String[]{
					"org.example.a.d.Class5",
			};
			String[] exportPackages = new String[]{
					"org.example.a.b.*",
					"org.example.a.c.*"
			};
			
			PackageMerger pm = new PackageMerger();
			for(String className:exportClasses){
				pm.addClass(className, true,false);
			}
			for(String className:otherClasses){
				pm.addClass(className, false,false);
			}
			String[] exportedPackages = pm.getExportPackages();
			
			assertArrayEquals(exportPackages,exportedPackages);
		}
		
		{
			String[] exportClasses = new String[]{
			};
			String[] otherClasses = new String[]{
					"org.example.a.d.Class5",
			};
			String[] exportPackages = new String[]{
			};
			
			PackageMerger pm = new PackageMerger();
			for(String className:exportClasses){
				pm.addClass(className, true,false);
			}
			for(String className:otherClasses){
				pm.addClass(className, false,false);
			}
			String[] exportedPackages = pm.getExportPackages();
			
			assertArrayEquals(exportPackages,exportedPackages);
		}
		
	}

}
